home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / sm099c.zip / EXAMPLE / EXAMPLE.SM < prev    next >
Text File  |  1996-04-05  |  32KB  |  701 lines

  1. /* =============================================================================
  2. A = Sourcefile
  3. B = Total number of lines
  4. C = Empty lines
  5. D = Commentlines
  6. E = Lines with code
  7. F = Functions
  8. G = Blocks of comment
  9.  
  10.        A:            B:      C:      D:      E:      F:      G:      Glob.lin.:
  11. --------------------------------------------------------------------------------
  12. F-1    example.c     26      7       12      7       1       2       G-1
  13. F-2    destroy.c     30      3       3       24      2       3       G-27
  14. F-3    init.c        79      8       2       69      2       6       G-57
  15. F-4    run.c         121     13      14      94      6       11      G-136
  16. F-5    utils.c       48      3       3       42      3       3       G-257
  17. F-6    vars.c        17      2       0       15      0       2       G-305
  18. F-7    wndproc.c     42      7       1       34      1       1       G-322
  19. --------------------------------------------------------------------------------
  20.        Totaly        363     43      35      285     15      28      
  21. ============================================================================= */
  22.  
  23.  
  24.  
  25. /* =============================================================================
  26. Index of functions:
  27.  
  28. F-1    ClientWndProc ()    G-325    (L-4:    wndproc.c)
  29. F-2    ClrScr ()    G-280    (L-24:    utils.c)
  30. F-3    GetScrSize ()    G-259    (L-3:    utils.c)
  31. F-4    InitScreen ()    G-95    (L-39:    init.c)
  32. F-5    Initialize ()    G-59    (L-3:    init.c)
  33. F-6    MoveHorizontally ()    G-189    (L-54:    run.c)
  34. F-7    MoveVertically ()    G-209    (L-74:    run.c)
  35. F-8    PaintBall ()    G-228    (L-93:    run.c)
  36. F-9    Pause ()    G-296    (L-40:    utils.c)
  37. F-10    RestoreScreen ()    G-29    (L-3:    destroy.c)
  38. F-11    Run ()    G-139    (L-4:    run.c)
  39. F-12    RunBall ()    G-178    (L-43:    run.c)
  40. F-13    RunBalls ()    G-157    (L-22:    run.c)
  41. F-14    Terminate ()    G-51    (L-25:    destroy.c)
  42. F-15    main ()    G-19    (L-19:    example.c) */
  43.  
  44.  
  45.  
  46. /* =============================================================================
  47. List of calling sequences:
  48.  
  49.  
  50. L-1    ClientWndProc ()
  51. L-2    |    ClrScr ()
  52. L-3    |    |    WinFillRect () External
  53. L-4    |    |    WinQueryWindowRect () External
  54. L-5    |    |    cleardevice () External
  55. L-6    |    |    clrscr () External
  56. L-7    |    GetScrSize ()
  57. L-8    |    |    WinQueryWindowRect () External
  58. L-9    |    |    getmaxx () External
  59. L-10    |    |    getmaxy () External
  60. L-11    |    |    gettextinfo () External
  61. L-12    |    MRFROMLONG () External
  62. L-13    |    PaintBall ()
  63. L-14    |    |    GpiFullArc () External
  64. L-15    |    |    GpiMove () External
  65. L-16    |    |    GpiSetColor () External
  66. L-17    |    |    MAKEFIXED () External
  67. L-18    |    |    circle () External
  68. L-19    |    |    gotoxy () External
  69. L-20    |    |    putch () External
  70. L-21    |    |    setcolor () External
  71. L-22    |    |    textcolor () External
  72. L-23    |    RunBalls ()
  73. L-24    |    |    RunBall ()
  74. L-25    |    |    |    MoveHorizontally ()
  75. L-26    |    |    |    |    NEWCOLOR () External
  76. L-27    |    |    |    |    NEWSPEED () External
  77. L-28    |    |    |    MoveVertically ()
  78. L-29    |    |    |    |    NEWSPEED () External
  79. L-30    |    |    |    PaintBall () ... [L-13]
  80. L-31    |    |    WinQueryFocus () External
  81. L-32    |    WinBeginPaint () External
  82. L-33    |    WinDefWindowProc () External
  83. L-34    |    WinEndPaint () External
  84.  
  85.  
  86. --------------------------------------------------------------------------------
  87. L-35    main ()
  88. L-36    |    Initialize ()
  89. L-37    |    |    InitScreen ()
  90. L-38    |    |    |    ClrScr () ... [L-2]
  91. L-39    |    |    |    DosSetPriority () External
  92. L-40    |    |    |    GetScrSize () ... [L-7]
  93. L-41    |    |    |    GpiCreatePS () External
  94. L-42    |    |    |    GpiSetArcParams () External
  95. L-43    |    |    |    GpiSetDrawingMode () External
  96. L-44    |    |    |    WinCreateMsgQueue () External
  97. L-45    |    |    |    WinCreateStdWindow () External
  98. L-46    |    |    |    WinInitialize () External
  99. L-47    |    |    |    WinOpenWindowDC () External
  100. L-48    |    |    |    WinRegisterClass () External
  101. L-49    |    |    |    WinStartTimer () External
  102. L-50    |    |    |    _setcursortype () External
  103. L-51    |    |    |    cprintf () External
  104. L-52    |    |    |    exit () External
  105. L-53    |    |    |    grapherrormsg () External
  106. L-54    |    |    |    graphresult () External
  107. L-55    |    |    |    initgraph () External
  108. L-56    |    |    NEWCOLOR () External
  109. L-57    |    |    NEWSPEED () External
  110. L-58    |    |    atoi () External
  111. L-59    |    |    memset () External
  112. L-60    |    |    random () External
  113. L-61    |    |    randomize () External
  114. L-62    |    Run ()
  115. L-63    |    |    Pause ()
  116. L-64    |    |    |    DosSleep () External
  117. L-65    |    |    |    delay () External
  118. L-66    |    |    RunBalls () ... [L-23]
  119. L-67    |    |    WinDispatchMsg () External
  120. L-68    |    |    WinGetMsg () External
  121. L-69    |    |    getch () External
  122. L-70    |    |    kbhit () External
  123. L-71    |    Terminate ()
  124. L-72    |    |    RestoreScreen ()
  125. L-73    |    |    |    ClrScr () ... [L-2]
  126. L-74    |    |    |    WinDestroyMsgQueue () External
  127. L-75    |    |    |    WinDestroyWindow () External
  128. L-76    |    |    |    WinReleasePS () External
  129. L-77    |    |    |    WinStopTimer () External
  130. L-78    |    |    |    WinTerminate () External
  131. L-79    |    |    |    _setcursortype () External
  132. L-80    |    |    |    closegraph () External
  133. L-81    |    |    |    gotoxy () External
  134. L-82    |    |    |    normvideo () External
  135.  
  136.  
  137.  
  138. --------------------------------------------------------------------------------
  139. Index to list of calling sequences:
  140.  
  141.  
  142. F-1    ClientWndProc ()    L-1
  143. F-2    ClrScr ()    L-2
  144. F-3    GetScrSize ()    L-7
  145. F-4    InitScreen ()    L-37
  146. F-5    Initialize ()    L-36
  147. F-6    MoveHorizontally ()    L-25
  148. F-7    MoveVertically ()    L-28
  149. F-8    PaintBall ()    L-13
  150. F-9    Pause ()    L-63
  151. F-10    RestoreScreen ()    L-72
  152. F-11    Run ()    L-62
  153. F-12    RunBall ()    L-24
  154. F-13    RunBalls ()    L-23
  155. F-14    Terminate ()    L-71
  156. F-15    main ()    L-35 */
  157.  
  158.  
  159.  
  160. /* =============================================================================
  161. Sourcefile...........: example.c
  162. Total number of lines: 26
  163. Empty lines..........: 7     (26%)
  164. Commentlines.........: 12    (46%)
  165. Lines with code......: 7     (26%)
  166. Functions............: 1
  167. Blocks of comment....: 2 */
  168.  
  169.  
  170.  
  171. /* G-1      L-1      Comment  | *//* --------------------------------------------------------------------------
  172.    G-2      L-2      Comment  |   ** This dummy program is just developed as an example source code for the
  173.    G-3      L-3      Comment  |   ** Source Mapper (SM). The program is divided into more functions than
  174.    G-4      L-4      Comment  |   ** actually makes sense. That's just to have functions enough to show you
  175.    G-5      L-5      Comment  |   ** what SM can do.
  176.    G-6      L-6      Comment  |   **
  177.    G-7      L-7      Comment  |   ** Compiler options:
  178.    G-8      L-8      Comment  |   ** OS2 = Compile for OS/2.
  179.    G-9      L-9      Comment  |   ** DOS = Compile for grand old DOS.
  180.    G-10     L-10     Comment  |   ** GUI = Compile GUI version (supported for both DOS and OS2 version).
  181.    G-11     L-11     Comment  |   ** ------------------------------------------------------------------------ */
  182. /* G-12     L-12              | */
  183. /* G-13     L-13              | */
  184. /* G-14     L-14              | */
  185.                                   #include "example.h"
  186. /* G-16     L-16              | */
  187. /* G-17     L-17              | */
  188. /* G-18     L-18              | */
  189. /* G-19     L-19              | */void main ( int iArgC, char *pcArgP[] )
  190. /* G-20     L-20     Comment  | *//* Program entry point.  */
  191. /*
  192.                                   List of callers of 'main ()':
  193.  
  194.                                   No caller
  195. */
  196. /* G-21     L-21              | */{
  197. /* G-22     L-22     B1       | */   Initialize (iArgC, pcArgP, &Balls);
  198. /* G-23     L-23     B1       | */   Run (&Balls);
  199. /* G-24     L-24     B1       | */   Terminate ();
  200. /* G-25     L-25              | */}
  201. /* G-26     L-26              | */
  202.  
  203.  
  204.  
  205. /* =============================================================================
  206. Sourcefile...........: destroy.c
  207. Total number of lines: 30
  208. Empty lines..........: 3     (10%)
  209. Commentlines.........: 3     (10%)
  210. Lines with code......: 24    (80%)
  211. Functions............: 2
  212. Blocks of comment....: 3 */
  213.  
  214.  
  215.  
  216.                                   #include "example.h"
  217. /* G-28     L-2               | */
  218. /* G-29     L-3               | */void RestoreScreen ( void )
  219. /* G-30     L-4      Comment  | *//* Restore screen (color, mode, etc.) back to what it was when the program
  220.    G-31     L-5      Comment  |      was started. */
  221. /*
  222.                                   List of callers of 'RestoreScreen ()':
  223.  
  224.                                   Terminate ()    G-51
  225. */
  226. /* G-32     L-6               | */{
  227.                                      #ifdef GUI
  228.                                      #ifdef OS2
  229. /* G-35     L-9      B1       | */   WinStopTimer (hAB, hWndClient, TID_MOVE);
  230. /* G-36     L-10     B1       | */   WinReleasePS (hPS);
  231. /* G-37     L-11     B1       | */   WinDestroyWindow (hWndFrame);
  232. /* G-38     L-12     B1       | */   WinDestroyMsgQueue (hMQ);
  233. /* G-39     L-13     B1       | */   WinTerminate (hAB);
  234.                                      #else
  235. /* G-41     L-15     B1       | */   closegraph (); /* Return the system to text mode */
  236.                                      #endif
  237.                                      #else
  238. /* G-44     L-18     B1       | */   ClrScr ();
  239. /* G-45     L-19     B1       | */   normvideo ();
  240. /* G-46     L-20     B1       | */   gotoxy (0, iScreenH - 1);
  241. /* G-47     L-21     B1       | */   _setcursortype (_NORMALCURSOR);
  242.                                      #endif
  243. /* G-49     L-23              | */}
  244. /* G-50     L-24              | */
  245. /* G-51     L-25              | */void Terminate ( void )
  246. /* G-52     L-26     Comment  | *//* Get ready to exit this silly program */
  247. /*
  248.                                   List of callers of 'Terminate ()':
  249.  
  250.                                   main ()    G-19
  251. */
  252. /* G-53     L-27              | */{
  253. /* G-54     L-28     B1       | */   RestoreScreen ();
  254. /* G-55     L-29              | */}
  255. /* G-56     L-30              | */
  256.  
  257.  
  258.  
  259. /* =============================================================================
  260. Sourcefile...........: init.c
  261. Total number of lines: 79
  262. Empty lines..........: 8     (10%)
  263. Commentlines.........: 2     (2%)
  264. Lines with code......: 69    (87%)
  265. Functions............: 2
  266. Blocks of comment....: 6 */
  267.  
  268.  
  269.  
  270.                                   #include "example.h"
  271. /* G-58     L-2               | */
  272. /* G-59     L-3               | */void Initialize ( int iArgC, char *pcArgP[], BALLS *pBalls )
  273. /* G-60     L-4      Comment  | *//* Perform everything that's neccessary to run the balls. */
  274. /*
  275.                                   List of callers of 'Initialize ()':
  276.  
  277.                                   main ()    G-19
  278. */
  279. /* G-61     L-5               | */{
  280. /* G-62     L-6      B1       | */   int iC1;
  281. /* G-63     L-7      B1       | */   BALL *pBall;
  282. /* G-64     L-8               | */
  283. /* G-65     L-9      B1       | */   memset (pBalls, 0, sizeof (BALLS));
  284. /* G-66     L-10              | */
  285. /* G-67     L-11     B1       | */   InitScreen ();
  286. /* G-68     L-12              | */
  287. /* G-69     L-13     B1       | */   randomize ();
  288. /* G-70     L-14              | */
  289. /* G-71     L-15     B1       | */   for (iC1 = 0;
  290. /* G-72     L-16     B1       | */        iC1 < MAXBALLS;
  291. /* G-73     L-17     B1       | */        iC1++)
  292. /* G-74     L-18     B1       | */   {
  293. /* G-75     L-19     B-2      | */      pBall = &pBalls->Ball[iC1];
  294. /* G-76     L-20     B-2      | */      NEWCOLOR (pBall->iColor);
  295. /* G-77     L-21     B-2      | */      pBall->iXPos = random (iScreenW) + 1;
  296. /* G-78     L-22     B-2      | */      pBall->iYPos = random (iScreenH) + 1;
  297. /* G-79     L-23     B-2      | */      pBall->iHSpeed = (iC1%2) ? NEWSPEED (MAXHSPEED) : -NEWSPEED (MAXHSPEED);
  298. /* G-80     L-24     B-2      | */      pBall->iVSpeed = (iC1%2) ? NEWSPEED (MAXVSPEED) : -NEWSPEED (MAXVSPEED);
  299. /* G-81     L-25     B1       | */   }
  300. /* G-82     L-26              | */
  301. /* G-83     L-27     B1       | */   if (iArgC > 1)
  302. /* G-84     L-28     B1       | */   {
  303. /* G-85     L-29     B-2      | */      pBalls->iNr = atoi (pcArgP[1]);
  304. /* G-86     L-30     B-2      | */      pBalls->iNr = pBalls->iNr > 0 ? pBalls->iNr : 10;
  305. /* G-87     L-31     B-2      | */      pBalls->iNr = pBalls->iNr <= MAXBALLS ? pBalls->iNr : MAXBALLS;
  306. /* G-88     L-32     B1       | */   }
  307. /* G-89     L-33     B1       | */   else
  308. /* G-90     L-34     B1       | */   {
  309. /* G-91     L-35     B-2      | */      pBalls->iNr = 10;
  310. /* G-92     L-36     B1       | */   }
  311. /* G-93     L-37              | */}
  312. /* G-94     L-38              | */
  313. /* G-95     L-39              | */void InitScreen ( void )
  314. /* G-96     L-40     Comment  | *//* Prepare screen to show the running balls. */
  315. /*
  316.                                   List of callers of 'InitScreen ()':
  317.  
  318.                                   Initialize ()    G-59
  319. */
  320. /* G-97     L-41              | */{
  321.                                      #ifdef GUI
  322.                                      #ifdef OS2
  323. /* G-100    L-44     B1       | */   SIZEL Size = { 0, 0 };
  324. /* G-101    L-45     B1       | */   ARCPARAMS ap = { 4, 4, 0, 0 };
  325. /* G-102    L-46     B1       | */   hAB = WinInitialize (0);
  326. /* G-103    L-47     B1       | */   hMQ = WinCreateMsgQueue (hAB, 0);
  327. /* G-104    L-48     B1       | */   WinRegisterClass (hAB, "SillyExample", ClientWndProc, CS_SIZEREDRAW, 0);
  328. /* G-105    L-49     B1       | */   hWndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE | WS_ANIMATE,
  329. /* G-106    L-50     B1       | */                                   &ulFrameFlags,
  330. /* G-107    L-51     B1       | */                                   "SillyExample", "Bounching balls",
  331. /* G-108    L-52     B1       | */                                   0, 0, 100, &hWndClient);
  332. /* G-109    L-53     B1       | */   hDC = WinOpenWindowDC (hWndClient);
  333. /* G-110    L-54     B1       | */   hPS = GpiCreatePS (hAB, hDC, &Size, PU_PELS | GPIF_DEFAULT |
  334. /* G-111    L-55     B1       | */                                       GPIT_MICRO | GPIA_ASSOC);
  335. /* G-112    L-56     B1       | */   GpiSetDrawingMode (hPS, DM_DRAW);
  336. /* G-113    L-57     B1       | */   WinStartTimer (hAB, hWndClient, TID_MOVE, DELAY);
  337. /* G-114    L-58     B1       | */   GpiSetArcParams (hPS, &ap);
  338. /* G-115    L-59     B1       | */   DosSetPriority (0, 1, 31, 0); /* Change to a low priority (IDLE class) */
  339.                                      #else
  340. /* G-117    L-61     B1       | */   int iErrorCode;
  341. /* G-118    L-62     B1       | */   int iGraphDriver;
  342. /* G-119    L-63     B1       | */   int iGraphMode;
  343. /* G-120    L-64              | */
  344. /* G-121    L-65     B1       | */   iGraphDriver = DETECT;        /* Request auto-detection */
  345. /* G-122    L-66     B1       | */   initgraph (&iGraphDriver, &iGraphMode, "");
  346. /* G-123    L-67     B1       | */   iErrorCode = graphresult ();  /* Read result of initialization */
  347. /* G-124    L-68     B1       | */   if (iErrorCode != grOk)       /* Error occured during init */
  348. /* G-125    L-69     B1       | */   {
  349. /* G-126    L-70     B-2      | */      cprintf ("Graphics System Error: %s\n\r", grapherrormsg (iErrorCode));
  350. /* G-127    L-71     B-2      | */      exit (1);
  351. /* G-128    L-72     B1       | */   }
  352.                                      #endif
  353.                                      #else
  354. /* G-131    L-75     B1       | */   _setcursortype (_NOCURSOR);
  355.                                      #endif
  356. /* G-133    L-77     B1       | */   ClrScr ();
  357. /* G-134    L-78     B1       | */   GetScrSize (&iScreenW, &iScreenH);
  358. /* G-135    L-79              | */}
  359.  
  360.  
  361.  
  362. /* =============================================================================
  363. Sourcefile...........: run.c
  364. Total number of lines: 121
  365. Empty lines..........: 13    (10%)
  366. Commentlines.........: 14    (11%)
  367. Lines with code......: 94    (77%)
  368. Functions............: 6
  369. Blocks of comment....: 11 */
  370.  
  371.  
  372.  
  373.                                   #include "example.h"
  374. /* G-137    L-2               | */
  375.                                   #pragma argsused
  376. /* G-139    L-4               | */void Run ( BALLS *pBalls )
  377. /* G-140    L-5      Comment  | *//* Main loop of the program. */
  378. /*
  379.                                   List of callers of 'Run ()':
  380.  
  381.                                   main ()    G-19
  382. */
  383. /* G-141    L-6               | */{
  384.                                      #if defined (OS2) && defined (GUI)
  385. /* G-143    L-8      B1       | */   while (WinGetMsg (hAB, &QMsg, 0, 0, 0))
  386. /* G-144    L-9      B1       | */   {
  387. /* G-145    L-10     B-2      | */      WinDispatchMsg (hAB, &QMsg);
  388. /* G-146    L-11     B1       | */   }
  389.                                      #else
  390. /* G-148    L-13     B1       | */   while (!kbhit ())
  391. /* G-149    L-14     B1       | */   {
  392. /* G-150    L-15     B-2      | */      RunBalls (pBalls);
  393. /* G-151    L-16     B-2      | */      Pause (DELAY);
  394. /* G-152    L-17     B1       | */   }
  395. /* G-153    L-18     B1       | */   getch ();   /* Remove that termination key from keyboard buffer */
  396.                                      #endif
  397. /* G-155    L-20              | */}
  398. /* G-156    L-21              | */
  399. /* G-157    L-22              | */void RunBalls ( BALLS *pBalls )
  400. /* G-158    L-23     Comment  | *//* Let every running ball take a new step. Heading to their current direction,
  401.    G-159    L-24     Comment  |      and moving in their current speed. Change direction of each ball so that
  402.    G-160    L-25     Comment  |      no balls run outside visible screen area. */
  403. /*
  404.                                   List of callers of 'RunBalls ()':
  405.  
  406.                                   Run ()    G-139
  407.                                   ClientWndProc ()    G-325
  408. */
  409. /* G-161    L-26              | */{
  410. /* G-162    L-27     B1       | */   int iC1;
  411. /* G-163    L-28              | */
  412.                                      #if defined (OS2) && defined (GUI)
  413. /* G-165    L-30     B1       | */   if (WinQueryFocus (HWND_DESKTOP) != hWndClient)
  414. /* G-166    L-31     B1       | */   {
  415. /* G-167    L-32     Comment  | */      /* Don't hogg the single input queue of OS/2 when user work in some
  416.    G-168    L-33     Comment  |            other window than this stupid one. */
  417. /* G-169    L-34     B-2      | */      return;     
  418. /* G-170    L-35     B1       | */   }
  419.                                      #endif
  420. /* G-172    L-37              | */
  421. /* G-173    L-38     B1       | */   for (iC1 = 0;
  422. /* G-174    L-39     B1       | */        iC1 < pBalls->iNr;
  423. /* G-175    L-40     B1       | */        RunBall (&pBalls->Ball[iC1++]));
  424. /* G-176    L-41              | */}
  425. /* G-177    L-42              | */
  426. /* G-178    L-43              | */void RunBall ( BALL *pBall )
  427. /* G-179    L-44     Comment  | *//* Kernel function of RunBalls(). */
  428. /*
  429.                                   List of callers of 'RunBall ()':
  430.  
  431.                                   RunBalls ()    G-157
  432. */
  433. /* G-180    L-45              | */{
  434. /* G-181    L-46     B1       | */   PaintBall (pBall, BLACK);         /* Hide the ball from old position */
  435. /* G-182    L-47              | */
  436. /* G-183    L-48     B1       | */   MoveHorizontally (pBall);
  437. /* G-184    L-49     B1       | */   MoveVertically (pBall);
  438. /* G-185    L-50              | */
  439. /* G-186    L-51     B1       | */   PaintBall (pBall, pBall->iColor); /* Show the ball at new position */
  440. /* G-187    L-52              | */}
  441. /* G-188    L-53              | */
  442. /* G-189    L-54              | */void MoveHorizontally ( BALL *pBall )
  443. /* G-190    L-55     Comment  | *//* Move specified ball left/right.
  444.    G-191    L-56     Comment  |      Change speed and direction when the  ball reach any edge of screen. */
  445. /*
  446.                                   List of callers of 'MoveHorizontally ()':
  447.  
  448.                                   RunBall ()    G-178
  449. */
  450. /* G-192    L-57              | */{
  451. /* G-193    L-58     B1       | */   pBall->iXPos += pBall->iHSpeed;
  452. /* G-194    L-59              | */
  453. /* G-195    L-60     B1       | */   if (pBall->iXPos > iScreenW)
  454. /* G-196    L-61     B1       | */   {
  455. /* G-197    L-62     B-2      | */      pBall->iHSpeed = -NEWSPEED (MAXHSPEED);
  456. /* G-198    L-63     B-2      | */      pBall->iXPos = iScreenW;
  457. /* G-199    L-64     B-2      | */      NEWCOLOR (pBall->iColor);
  458. /* G-200    L-65     B1       | */   }
  459. /* G-201    L-66     B1       | */   else
  460. /* G-202    L-67     B1       | */   if (pBall->iXPos <= 0)
  461. /* G-203    L-68     B1       | */   {
  462. /* G-204    L-69     B-2      | */      pBall->iXPos = 1;
  463. /* G-205    L-70     B-2      | */      pBall->iHSpeed = NEWSPEED (MAXHSPEED);
  464. /* G-206    L-71     B1       | */   }
  465. /* G-207    L-72              | */}
  466. /* G-208    L-73              | */
  467. /* G-209    L-74              | */void MoveVertically ( BALL *pBall )
  468. /* G-210    L-75     Comment  | *//* Move specified ball up/down.
  469.    G-211    L-76     Comment  |      Change speed and direction when the  ball reach any edge of screen. */
  470. /*
  471.                                   List of callers of 'MoveVertically ()':
  472.  
  473.                                   RunBall ()    G-178
  474. */
  475. /* G-212    L-77              | */{
  476. /* G-213    L-78     B1       | */   pBall->iYPos += pBall->iVSpeed;
  477. /* G-214    L-79              | */
  478. /* G-215    L-80     B1       | */   if (pBall->iYPos > iScreenH)
  479. /* G-216    L-81     B1       | */   {
  480. /* G-217    L-82     B-2      | */      pBall->iYPos = iScreenH;
  481. /* G-218    L-83     B-2      | */      pBall->iVSpeed = -NEWSPEED (MAXVSPEED);
  482. /* G-219    L-84     B1       | */   }
  483. /* G-220    L-85     B1       | */   else
  484. /* G-221    L-86     B1       | */   if (pBall->iYPos <= 0)
  485. /* G-222    L-87     B1       | */   {
  486. /* G-223    L-88     B-2      | */      pBall->iYPos = 1;
  487. /* G-224    L-89     B-2      | */      pBall->iVSpeed = NEWSPEED (MAXVSPEED);
  488. /* G-225    L-90     B1       | */   }
  489. /* G-226    L-91              | */}
  490. /* G-227    L-92              | */
  491. /* G-228    L-93              | */void PaintBall ( BALL *pBall, int iColor )
  492. /* G-229    L-94     Comment  | *//* Paint specified ball at its current position, using specified color */
  493. /*
  494.                                   List of callers of 'PaintBall ()':
  495.  
  496.                                   RunBall ()    G-178
  497.                                   ClientWndProc ()    G-325
  498. */
  499. /* G-230    L-95              | */{
  500.                                      #ifdef GUI
  501.                                      #ifdef OS2
  502. /* G-233    L-98     B1       | */   POINTL pt;
  503. /* G-234    L-99     B1       | */   pt.x = pBall->iXPos;
  504. /* G-235    L-100    B1       | */   pt.y = pBall->iYPos;
  505. /* G-236    L-101    B1       | */   GpiMove (hPS, &pt);
  506. /* G-237    L-102    B1       | */   GpiSetColor (hPS, iColor);
  507. /* G-238    L-103    B1       | */   GpiFullArc (hPS, DRO_OUTLINE, MAKEFIXED (1, 0));
  508.                                      #else
  509. /* G-240    L-105    B1       | */   setcolor (iColor);
  510. /* G-241    L-106    B1       | */   circle (pBall->iXPos, pBall->iYPos, 5);
  511.                                      #endif
  512.                                      #else
  513. /* G-244    L-109    Comment  | */   /* Prevent text screen from being vertically scrolled if the ball is
  514.    G-245    L-110    Comment  |         positioned at bottom right corner of screen (text modes only) */
  515. /* G-246    L-111    B1       | */   if ((pBall->iXPos == iScreenW) &&
  516. /* G-247    L-112    B1       | */       (pBall->iYPos == iScreenH))
  517. /* G-248    L-113    B1       | */   {
  518. /* G-249    L-114    B-2      | */      return;
  519. /* G-250    L-115    B1       | */   }
  520. /* G-251    L-116             | */
  521. /* G-252    L-117    B1       | */   textcolor (iColor);
  522. /* G-253    L-118    B1       | */   gotoxy (pBall->iXPos, pBall->iYPos);
  523. /* G-254    L-119    B1       | */   putch ('*');
  524.                                      #endif
  525. /* G-256    L-121             | */}
  526.  
  527.  
  528.  
  529. /* =============================================================================
  530. Sourcefile...........: utils.c
  531. Total number of lines: 48
  532. Empty lines..........: 3     (6%)
  533. Commentlines.........: 3     (6%)
  534. Lines with code......: 42    (87%)
  535. Functions............: 3
  536. Blocks of comment....: 3 */
  537.  
  538.  
  539.  
  540.                                   #include "example.h"
  541. /* G-258    L-2               | */
  542. /* G-259    L-3               | */void GetScrSize ( int *piScrW, int *piScrH )
  543. /* G-260    L-4      Comment  | *//* Fetch out current width and height of screen */
  544. /*
  545.                                   List of callers of 'GetScrSize ()':
  546.  
  547.                                   InitScreen ()    G-95
  548.                                   ClientWndProc ()    G-325
  549. */
  550. /* G-261    L-5               | */{
  551.                                      #ifdef GUI
  552.                                      #ifdef OS2
  553. /* G-264    L-8      B1       | */   RECTL Rect;
  554. /* G-265    L-9      B1       | */   WinQueryWindowRect (hWndClient, &Rect);
  555. /* G-266    L-10     B1       | */   *piScrW = Rect.xRight;
  556. /* G-267    L-11     B1       | */   *piScrH = Rect.yTop;
  557.                                      #else
  558. /* G-269    L-13     B1       | */   *piScrW = getmaxx ();
  559. /* G-270    L-14     B1       | */   *piScrH = getmaxy ();
  560.                                      #endif
  561.                                      #else
  562. /* G-273    L-17     B1       | */   struct text_info ti;
  563. /* G-274    L-18     B1       | */   gettextinfo (&ti);
  564. /* G-275    L-19     B1       | */   *piScrW = ti.screenwidth;
  565. /* G-276    L-20     B1       | */   *piScrH = ti.screenheight;
  566.                                      #endif
  567. /* G-278    L-22              | */}
  568. /* G-279    L-23              | */
  569. /* G-280    L-24              | */void ClrScr ( void )
  570. /* G-281    L-25     Comment  | *//* Clear the screen */
  571. /*
  572.                                   List of callers of 'ClrScr ()':
  573.  
  574.                                   RestoreScreen ()    G-29
  575.                                   InitScreen ()    G-95
  576.                                   ClientWndProc ()    G-325
  577. */
  578. /* G-282    L-26              | */{
  579.                                      #ifdef GUI
  580.                                      #ifdef OS2
  581. /* G-285    L-29     B1       | */   RECTL Rect;
  582. /* G-286    L-30     B1       | */   WinQueryWindowRect (hWndClient, &Rect);
  583. /* G-287    L-31     B1       | */   WinFillRect (hPS, &Rect, CLR_BLACK);
  584.                                      #else
  585. /* G-289    L-33     B1       | */   cleardevice ();
  586.                                      #endif
  587.                                      #else
  588. /* G-292    L-36     B1       | */   clrscr ();
  589.                                      #endif
  590. /* G-294    L-38              | */}
  591. /* G-295    L-39              | */
  592. /* G-296    L-40              | */void Pause ( int iMilliSeconds )
  593. /* G-297    L-41     Comment  | *//* Sleep specified number of milliseconds */
  594. /*
  595.                                   List of callers of 'Pause ()':
  596.  
  597.                                   Run ()    G-139
  598. */
  599. /* G-298    L-42              | */{
  600.                                      #ifdef OS2
  601. /* G-300    L-44     B1       | */   DosSleep (iMilliSeconds);
  602.                                      #else
  603. /* G-302    L-46     B1       | */   delay (iMilliSeconds);
  604.                                      #endif
  605. /* G-304    L-48              | */}
  606.  
  607.  
  608.  
  609. /* =============================================================================
  610. Sourcefile...........: vars.c
  611. Total number of lines: 17
  612. Empty lines..........: 2     (11%)
  613. Commentlines.........: 0     (0%)
  614. Lines with code......: 15    (88%)
  615. Functions............: 0
  616. Blocks of comment....: 2 */
  617.  
  618.  
  619.  
  620.                                   #include "example.h"
  621. /* G-306    L-2               | */
  622. /* G-307    L-3               | */int iScreenW;              /* Width of screen */
  623. /* G-308    L-4               | */int iScreenH;              /* Height of screen */
  624. /* G-309    L-5               | */BALLS Balls;
  625. /* G-310    L-6               | */
  626.                                   #if defined (OS2) && defined (GUI)
  627. /* G-312    L-8               | */HAB hAB;
  628. /* G-313    L-9               | */HMQ hMQ;
  629. /* G-314    L-10              | */HPS hPS;
  630. /* G-315    L-11              | */HDC hDC;
  631. /* G-316    L-12              | */QMSG QMsg;
  632. /* G-317    L-13              | */HWND hWndFrame;
  633. /* G-318    L-14              | */HWND hWndClient;
  634. /* G-319    L-15              | */ULONG ulFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER |
  635. /* G-320    L-16              | */                     FCF_MINMAX | FCF_SHELLPOSITION | FCF_TASKLIST | FCF_ICON;
  636.                                   #endif
  637.  
  638.  
  639.  
  640. /* =============================================================================
  641. Sourcefile...........: wndproc.c
  642. Total number of lines: 42
  643. Empty lines..........: 7     (16%)
  644. Commentlines.........: 1     (2%)
  645. Lines with code......: 34    (80%)
  646. Functions............: 1
  647. Blocks of comment....: 1 */
  648.  
  649.  
  650.  
  651.                                   #include "example.h"
  652. /* G-323    L-2               | */
  653.                                   #if defined (OS2) && defined (GUI)
  654. /* G-325    L-4               | */MRESULT EXPENTRY ClientWndProc ( HWND hWnd, ULONG ulMsg,
  655. /* G-326    L-5               | */                                 MPARAM mp1, MPARAM mp2 )
  656. /* G-327    L-6      Comment  | *//* Handle OS2 PM messages. */
  657. /*
  658.                                   List of callers of 'ClientWndProc ()':
  659.  
  660.                                   No caller
  661. */
  662. /* G-328    L-7               | */{
  663. /* G-329    L-8      B1       | */   int iC1;
  664. /* G-330    L-9      B1       | */   HPS hPS;
  665. /* G-331    L-10              | */
  666. /* G-332    L-11     B1       | */   switch (ulMsg)
  667. /* G-333    L-12     B1       | */   {
  668. /* G-334    L-13     B-2      | */      case WM_TIMER:
  669. /* G-335    L-14     B-2      | */           RunBalls (&Balls);
  670. /* G-336    L-15     B-2      | */           break;
  671. /* G-337    L-16              | */
  672. /* G-338    L-17     B-2      | */      case WM_SIZE:
  673. /* G-339    L-18     B-2      | */           GetScrSize (&iScreenW, &iScreenH);
  674. /* G-340    L-19     B-2      | */           break;
  675. /* G-341    L-20              | */
  676. /* G-342    L-21     B-2      | */      case WM_PAINT:
  677. /* G-343    L-22     B-2      | */           hPS = WinBeginPaint (hWnd, 0, 0);
  678. /* G-344    L-23     B-2      | */           for (iC1 = 0;
  679. /* G-345    L-24     B-2      | */                iC1 < Balls.iNr;
  680. /* G-346    L-25     B-2      | */                iC1++)
  681. /* G-347    L-26     B-2      | */           {
  682. /* G-348    L-27     B--3     | */              PaintBall (&Balls.Ball[iC1], Balls.Ball[iC1].iColor);
  683. /* G-349    L-28     B-2      | */           }
  684. /* G-350    L-29     B-2      | */           WinEndPaint (hPS);
  685. /* G-351    L-30     B-2      | */           break;
  686. /* G-352    L-31              | */
  687. /* G-353    L-32     B-2      | */      case WM_ERASEBACKGROUND:
  688. /* G-354    L-33     B-2      | */           ClrScr ();
  689. /* G-355    L-34     B-2      | */           break;
  690. /* G-356    L-35              | */
  691. /* G-357    L-36     B-2      | */      default:
  692. /* G-358    L-37     B-2      | */           return WinDefWindowProc (hWnd, ulMsg, mp1, mp2);
  693. /* G-359    L-38     B1       | */   }
  694. /* G-360    L-39              | */
  695. /* G-361    L-40     B1       | */   return MRFROMLONG (FALSE);
  696. /* G-362    L-41              | */}
  697.                                   #endif
  698.  
  699.  
  700.  
  701.